using System;
using System.Collections.Generic;
using System.Text;
using Hoshimi._Map_;
using System.Drawing;
using PH.Map;

namespace Hoshimi
{
    public class Irradiator
    {
        public enum Position
        {
            SupGauche   = 1,
            Sup         = 2,
            SupDroite   = 3,
            Droite      = 4,
            InfDroite   = 5,
            Inf         = 6,
            InfGauche   = 7,
            Gauche      = 8
        }

        #region variables
            protected MyPlayer myPlayer = null;
            protected int[,] map;
            protected int range = 3;
        #endregion

        #region Getters
            public MapManager myMapManager { get { return MapManager.getInstance(); } }       
        #endregion

        #region utils deplacement

            // test que tu sois pas en dehors de la matrice et caseVide(x, y)
            Boolean casePossible(Point pt)
            {
                return true; 
            }

            // retourne vrai si il y a un zero en (x, y) et faux sinon
            Boolean caseVide(Point pt)
            {
                return true;
            }

            // indique si entre (x,y) et le point Hoshimi ya un mur ( dans ce cas on irradie pas )
            Boolean yaUnMurEntreDeux(Point pt)
            {
                return true;
            }

            // deplacement : regarde si devant c'est une case vide 
            Point avancer(Point depuis)
            {
                return new Point(1, 1);
            }

            void irradierPoint(Point point)

            void faireUnTour(Point centerPoint , int diametre)
            {
                int longueurCote = 2 * diametre + 1;
                Position location = Position.SupGauche;
                int x, y;

                do
                {
                    switch (this.location)
                    {
                        case Position.SupGauche:
                            x = centerPoint.X - diametre;
                            y = centerPoint.Y - diametre;
                            for (int i = 0; i < longueurCote; i ++  )
                            {
                                irradierPoint( new Point(x,y) );
                            }
                            this.location  = Position.Sup;
                            break;
                        case Position.Sup:
                            this.location = Position.SupDroite;
                            break;
                        case Position.SupDroite:
                            this.location  = Position.Droite;
                            break;
                        case Position.Droite:
                            this.location  = Position.InfDroite; break;
                        case Position.InfDroite:
                            this.location  = Position.Inf;
                            break;
                        case Position.Inf:
                            this.location  = Position.InfGauche;
                            break;
                        case Position.InfGauche:
                            this.location  = Position.Gauche;
                            break;
                        case Position.Gauche:
                            this.location  = Position.SupGauche;
                            break;
                    }

                }
                while (location != Position.SupGauche);
            }

        #endregion

        #region Ctor
        public Irradiator()
        {
            MapNode[,] mGrid = myMapManager.myGrid;
            int xMax = myMapManager.myGrid.GetLength(0) ;
            int yMax = myMapManager.myGrid.GetLength(1) ;
            map = new int[ xMax , yMax ] ;
 
            //storing Hoshimi Points
            foreach (Entity entity in myPlayer.Tissue.Entities)
            {
                if(entity.EntityType == EntityEnum.HoshimiPoint)
                {
                    Point pt = (Point)entity.Location;

                    for (int diametre = 0; diametre < range; diametre++ )
                    {
                        faireUnTour(pt, diametre);
                    }
                }
            }

        }

        #endregion
    }

    

}
